package com.itheima.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.*;


import com.itheima.service.PermissionService1;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * @author Tony
 * @create 2021-12-07 20:46
 */
@Service(interfaceClass = PermissionService1.class)
public class PermissionServiceImpl1 implements PermissionService1 {


    @Autowired
    private PermissionDao1 permissionDao;

    @Autowired
    private MenuDao1 menuDao;

    @Autowired
    private RoleDao1 roleDao;


    @Override
    public List<Map<String,Object>> findAllPermission() {
        return permissionDao.findAllPermission();
    }

    @Override
    public void addForRole(Integer roleId,Integer[] permissionIds) {
        for (Integer permissionId : permissionIds) {
            if(permissionId!=null){
                permissionDao.setRoleAndPermission(roleId,permissionId);
            }
        }
    }

    @Override
    public Integer[] findPermissionIdByRoleId(Integer roleId) {
        return permissionDao.findPermissionIdByRoleId(roleId);
    }

    @Override
    public void deleteRoleAndPermissionById(Integer roleId) {
        permissionDao.deleteRoleAndPermissionById(roleId);
        menuDao.deleteRoleAndMenuById(roleId);
        roleDao.deleteRoleById(roleId);
    }

    @Override
    public void deletePermissionById(Integer roleId) {
        permissionDao.deletePermissionById(roleId);
    }

    @Override
    public void addPermissionById(Integer permissionId1, Integer roleId) {
        permissionDao.addPermissionById(permissionId1, roleId);
    }
}
